package cn.jroid.demo.entity;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;

public class UserList {
	
	private int cateId;
	private int newsCount;
	private int pageSize;
	private List<User> userList = new ArrayList<User>();
	
	public UserList() {
		
	}
	
	public int getCateId() {
		return cateId;
	}
	public void setCateId(int cateId) {
		this.cateId = cateId;
	}
	public int getNewsCount() {
		return newsCount;
	}
	public void setNewsCount(int newsCount) {
		this.newsCount = newsCount;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public List<User> getUserList() {
		return userList;
	}
	public void setUserList(List<User> userList) {
		this.userList = userList;
	}

	@Override
	public String toString() {
		return "UserList [cateId=" + cateId + ", newsCount=" + newsCount
				+ ", pageSize=" + pageSize + ", userList=" + userList + "]";
	}
	
	
	public static UserList parse(String jsonContent) {
		UserList userList = new UserList();
		List<User> list = new ArrayList<User>();
		try {
			JSONArray jsonArray = new JSONArray(jsonContent);
			for(int i=0; i<jsonArray.length(); i++) {
				User user = new User();
				user.setUsername(jsonArray.getJSONObject(i).getString("username"));
				user.setContent(jsonArray.getJSONObject(i).getString("content"));
				list.add(user);
			}
			userList.setUserList(list);
			userList.setNewsCount(jsonArray.length());
			userList.setCateId(30);
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return userList;
	}
	
}
